package children.health.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import children.health.bean.UserInfo;
import children.health.dao.ILoginDao;
import children.health.service.ILoginService;

@Service("loginService")
public class LoginServiceImpl implements ILoginService {

	@Autowired
	private ILoginDao loginDao;

	@Override
	public boolean isUserNameValid(String name, String pass) {
		List<UserInfo> list = loginDao.findByNameAndPass(name, pass);
		return list.size() > 0;
	}

	@Override
	public UserInfo saveUser(String name, String pass) {
		UserInfo info = new UserInfo(name, pass);
		return loginDao.save(info);
	}

	@Override
	public List<UserInfo> getAllUsers() {
		List<UserInfo> list = loginDao.findAll();
		return list;
	}

	@Override
	public boolean updatePass(String name, String newPass) {
		int result = loginDao.updatePass(name, newPass);
		return result > 0;
	}

	@Override
	public boolean removeUser(String name) {
		int result = loginDao.removeByName(name);
		return result > 0;
	}
}
